from django.db import models
from publish.models import OrderModels
from user.models import User
class Order(models.Model):
    order_status = {
        (1, "未接单"),
        (2, "处理中"),
        (3, "完成"),
        (4, "失效")
    }
    order_code = models.CharField(verbose_name="订单ID",max_length=32,unique=True)
    name = models.CharField(verbose_name="下单人",max_length=32)
    content = models.TextField(verbose_name="订单内容",max_length=256)
    phone = models.CharField(verbose_name="下单人手机号",max_length=11)
    price = models.DecimalField(verbose_name="订单价格",max_digits=8,decimal_places=2)
    date_time = models.DateTimeField(verbose_name="订单时间")
    status = models.SmallIntegerField(verbose_name="订单状态",choices=order_status)
    address = models.CharField(verbose_name="地址",max_length=256)
    created_time = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    updated_time = models.DateTimeField(verbose_name="更新时间", auto_now=True)
    order_model = models.ForeignKey(OrderModels,on_delete=models.SET_NULL,null=True)
    user = models.ForeignKey(User,models.CASCADE)
    class Meta:
        db_table = "moh_order"
        verbose_name = "订单表"
        verbose_name_plural = "订单表"
        ordering = ['-date_time']
    def __str__(self):
        return f"{self.order_code},{self.name},{self.content},{self.phone},{self.price},{self.status}"